require(['goSwiper','loading','wx-footer'], function(goSwiper,loading,wxFooter) {
	var ss_city = sessionStorage.getItem('indexCity');
	if(ss_city != '' && ss_city != null && ss_city != undefined){
		$("#cityName").text(ss_city);
	}else{
		$("#cityName").text(city);
	}
	//vue实例
	var index = new Vue({
		el: '#index',
		data: {
			bannerList: [],
			focusList1: [],
			focusList2: [],
			focusList3: [],
			provinceData:[],
			cityData: [],
			isProv: false,
			isCity: false,
			showLoading: false,
			apiUrl: wxUrl + '/v3.2/large/index',
			areaUrl: wxUrl + '/v3.2/addr/areaList',
			item: {
				params:{
					token: token,
					userToken: userToken,
					lng: longitude,
					lat: latitude
				}
			},
			areaItem: {
				params:{
					token: token,
					userToken: userToken,
					parentAreaId: ''
				}
			}
		},
		ready: function() {
	        this.getIndexData();
	    },
		methods: {
			getIndexData: function() {
				this.$http.get(this.apiUrl, this.item)
				.then(function(response) {
					var result = JSON.parse(response.body);
					if(result.data){
						var bannerData = result.data.banner;
						var focusData  = result.data.focusList;
						this.$set('bannerList', bannerData);
						var focusList1 = focusData.slice(0,3);
						var focusList2 = focusData.slice(3,6);
						var focusList3 = focusData.slice(6,9);
						this.$set('focusList1', focusList1);
						this.$set('focusList2', focusList2);
						this.$set('focusList3', focusList3);
					}
					if(result.data.banner == undefined){
						$('#bannerDiv').hide();
					}
					if(index.bannerList.length > 1){
						//顶部轮播图swiper
						setTimeout(function(){
							var swiper = new Swiper('.wz_swiper1', {
							    pagination: '.swiper-pagination',
							    paginationClickable: true,
							    autoplay: 3000,
							    autoplayDisableOnInteraction: false,
							    centeredSlides: true,
							    loop: true
							});
						},500);
					}
					//我的关注轮播swiper
					setTimeout(function(){
						var swiper = new Swiper('.wz_swiper2', {
						    paginationClickable: true,
						    autoplay: 3000,
						    autoplayDisableOnInteraction: false,
						    centeredSlides: true,
						    loop: true
						});
					},2000);
				});
			},
			getProvince: function(){
				$("#areaLayer").animate({"bottom": 0});
				$("#areaBox").scrollTop(0);
				this.areaItem.params.parentAreaId = '';
				this.isProv = true;
				this.isCity = false;
				//获取省份
				this.$http.get(this.areaUrl, this.areaItem)
				.then(function(response) {
					var result = JSON.parse(response.body);
					this.$set('provinceData', result.data.result);
				});
			},
			getCity: function(e){
				this.areaItem.params.parentAreaId = $(e.currentTarget).attr('id');
				this.isProv = false;
				this.isCity = true;
				$("#areaBox").scrollTop(0);
				//获取城市
				this.$http.get(this.areaUrl, this.areaItem)
				.then(function(response) {
					var result = JSON.parse(response.body);
					this.$set('cityData', result.data.result);
				});
			},
			overArea: function(e){
				this.isProv = false;
				this.isCity = false;
				$(e.currentTarget).addClass('focus');
				$("#areaLayer").animate({"bottom": "-100%"});
				var indexCity = $(e.currentTarget).text();
				$("#cityName").text(indexCity);
				sessionStorage.setItem('indexCity',indexCity);
				sessionStorage.setItem('indexCityId',$(e.currentTarget).attr('id'));
				$("#areaBox").scrollTop(0);
			}
		}
	});

	//当滚动条到banner的底部时改变搜索框背景颜色
	$(window).scroll(function(){
		var scrollTop = $(this).scrollTop();
		var bannerHeight = $('.wz_swiper').height();
		if(scrollTop > bannerHeight){
			$('header').css("background","#E12122");
		}else{
			opacity = scrollTop/bannerHeight * 1;
			$('header').css("background","rgba(255,33,34,"+opacity+")");
		}
	});
});
// 为可控制返回指定页面所有添加pushState
history.pushState({}, document.title, null);
pushVHistory();
window.addEventListener("popstate", function() {
    // 跳转到订单列表页面
	goBackVHistory();
});